export default (psdWidth = 750) => {
  const html = document.documentElement
  const meta = document.createElement('meta')
  meta.name = 'viewport'
  meta.content = 'width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1'
  html.firstElementChild.appendChild(meta)

  const recalc = () => {
    let width = html.clientWidth
    if (width > psdWidth) {
      width = psdWidth
    }
    html.dataset.width = width
    html.dataset.persent = 100 * (width / psdWidth)
    html.style.fontSize = 100 * (width / psdWidth) + 'px'
  }

  recalc()
  if (document.addEventListener) {
    window.addEventListener('orientationchange' in window ? 'orientationchange' : 'resize', recalc, false)
  }
}
